//
//  SDHSportsTestVC.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/10.
//

#import "SDHSportsTestVC.h"

@interface SDHSportsTestVC ()

@property (weak, nonatomic) IBOutlet UIImageView *imgView;
@property (weak, nonatomic) IBOutlet UIImageView *imgview2;
@property (weak, nonatomic) IBOutlet UIImageView *imgview3;
@property (weak, nonatomic) IBOutlet UIImageView *imgview4;
@property (weak, nonatomic) IBOutlet UIImageView *imgview5;
@property (weak, nonatomic) IBOutlet UIImageView *imgview6;

@property (strong, nonatomic) NSData *data1;
@property (strong, nonatomic) NSData *data2;
@property (strong, nonatomic) NSData *data3;
@property (strong, nonatomic) NSData *data4;
@property (strong, nonatomic) NSData *data5;
@property (strong, nonatomic) NSData *data6;

@end

@implementation SDHSportsTestVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    // https://tenfei01.cfp.cn/creative/vcg/veer/800water/veer-308378075.jpg
    // https://alifei04.cfp.cn/creative/vcg/veer/800water/veer-171237813.jpg
    // https://tenfei03.cfp.cn/creative/vcg/veer/800water/veer-310682557.jpg
    // https://alifei05.cfp.cn/creative/vcg/veer/800water/veer-168667624.jpg
    // https://alifei05.cfp.cn/creative/vcg/veer/800water/veer-313715514.jpg
    // https://tenfei05.cfp.cn/creative/vcg/veer/800water/veer-167621529.jpg
    
    NSString *imgUrl1 = @"https://tenfei01.cfp.cn/creative/vcg/veer/800water/veer-308378075.jpg";
    NSString *imgUrl2 = @"https://alifei04.cfp.cn/creative/vcg/veer/800water/veer-171237813.jpg";
    NSString *imgUrl3 = @"https://tenfei03.cfp.cn/creative/vcg/veer/800water/veer-310682557.jpg";
    NSString *imgUrl4 = @"https://alifei05.cfp.cn/creative/vcg/veer/800water/veer-168667624.jpg";
    NSString *imgUrl5 = @"https://alifei05.cfp.cn/creative/vcg/veer/800water/veer-313715514.jpg";
    NSString *imgUrl6 = @"https://tenfei05.cfp.cn/creative/vcg/veer/800water/veer-167621529.jpg";
    
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_t group = dispatch_group_create();
    
    __weak typeof(self) weakSelf = self;
    dispatch_async(queue, ^{
        NSLog(@"#########1 图片下载完成");
        weakSelf.data1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl1]];
       
        dispatch_sync(dispatch_get_main_queue(), ^{
            [weakSelf.imgView setImage:[UIImage imageWithData:weakSelf.data1]];
        });
    });
    dispatch_async(queue, ^{
        NSLog(@"#########2 图片下载完成");
        weakSelf.data2 = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl2]];
        
        dispatch_sync(dispatch_get_main_queue(), ^{
            [weakSelf.imgview2 setImage:[UIImage imageWithData:weakSelf.data2]];
        });
    });
    dispatch_async(queue, ^{
        NSLog(@"#########3 图片下载完成");
        weakSelf.data3 = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl3]];
        
        dispatch_sync(dispatch_get_main_queue(), ^{
            [weakSelf.imgview3 setImage:[UIImage imageWithData:weakSelf.data3]];
        });
    });
    
    dispatch_barrier_async(queue, ^{
        dispatch_async(queue, ^{
            NSLog(@"#########4 图片下载完成");
            weakSelf.data4 = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl4]];
            
            dispatch_sync(dispatch_get_main_queue(), ^{
                [weakSelf.imgview4 setImage:[UIImage imageWithData:weakSelf.data4]];
            });
        });

    });
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
